package testBitmap 
{
	import flash.display.Sprite;
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.Timer;
	import flash.events.TimerEvent;


 

	/**
	 * ...
	 * @author ...
	 */
	public class PixelDissolveTest extends Sprite 
	{
		private var bmd:BitmapData;
		private var tim:Timer;
		
		public function PixelDissolveTest() 
		{
			bmd = new BitmapData(100, 80, false, 0x00CCCCCC);
			var bitmap:Bitmap = new Bitmap(bmd);
			addChild(bitmap);

			tim = new Timer(20);
			tim.start();
			tim.addEventListener(TimerEvent.TIMER, timerHandler);
		}
		
		private function timerHandler(event:TimerEvent):void {
			var randomNum:Number = Math.floor(Math.random() * int.MAX_VALUE);
			dissolve(randomNum);
		}

		private function dissolve(randomNum:Number):void
		{
			var rect:Rectangle = bmd.rect;
			var pt:Point = new Point(0, 0);
			var numberOfPixels:uint = 100;
			var red:uint = 0x00FF0000;
			bmd.pixelDissolve(bmd, rect, pt, randomNum, numberOfPixels, red);
			var grayRegion:Rectangle = bmd.getColorBoundsRect(0xFFFFFFFF, 0x00CCCCCC, true);
			if (grayRegion.width == 0 && grayRegion.height == 0 ) 
			{
				tim.stop();
			}
		}
	}

}